
import { GpCmd } from "./systems/CmdSystem";
import { QuadTree } from "../../common/QuadTree";
import { EcsEntity } from "ecs-ts";
// import RAPIER from "@dimforge/rapier2d";

export namespace Sglt {

    export class WorldInfo {
        public pfGridWidth = 100
        public pfGridHeight = 100
        constructor(
            public seed = 123,
            public isMaster = true,
            public width = 4000,
            public height = 4000,
            public pfNodeWidth = 20,
            public rvoGlobalTime = 0
        ) {
            this.pfGridWidth = Math.round(this.width / this.pfNodeWidth)
            this.pfGridHeight = Math.round(this.height / this.pfNodeWidth)
        }

        gridPosToWorldPos(gridX: number, gridY: number) {
            return {
                x: (gridX - this.pfGridWidth / 2) * this.pfNodeWidth + this.pfNodeWidth / 2,
                y: (gridY - this.pfGridHeight / 2) * this.pfNodeWidth + this.pfNodeWidth / 2,
                z: 0
            }
        }

        worldPosToGridPos(worldX: number, worldY: number) {
            return {
                x: Math.floor(worldX / this.pfNodeWidth + this.pfGridWidth / 2),
                y: Math.floor(worldY / this.pfNodeWidth + this.pfGridHeight / 2),
                z: 0
            }
        }

        get worldBound() {
            return {
                x: -this.width / 2,
                y: -this.height / 2,
                width: this.width,
                height: this.height,
                xMin: -this.width / 2,
                yMin: -this.height / 2,
                xMax: this.width / 2,
                yMax: this.height / 2,
            }
        }
    }


    /**命令信息 */
    export class CommandInfo {
        constructor(
            public commandList: GpCmd<any>[] = [],
            public currentCommandIndex = 0,
            public waitSyncCommandList: GpCmd<any>[] = [],
        ) { }
    }

    export class UiInfo {
        constructor(
            public createEntityMap: { [key: string]: EcsEntity } = {},
            public removeEntityMap: { [key: string]: EcsEntity } = {},
        ) { }

        afterEntityCreated(ecsEntity) {
            this.createEntityMap[ecsEntity.id] = ecsEntity
            delete this.removeEntityMap[ecsEntity.id]
        }

        beforeEntityRemove(ecsEntity) {
            this.removeEntityMap[ecsEntity.id] = ecsEntity
            delete this.createEntityMap[ecsEntity.id]
        }
    }

    export class RapierInfo {
        public world: any// RAPIER.World
        constructor(
            RAPIER: any//
        ) {
            this.world = new RAPIER.World(new RAPIER.Vector2(0, 0))
        }
    }

}